<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Admin\Controller;
use Think\Controller;

class FilmController extends BaseController {
	/*
	 * 电影列表
	 */
    public function flist(){
		
    	$m = M('ehrcompany_singer_resource_video',null,'ODDH5_DB_CONFIG1');
    	$where['type'] = 6;
    	$count = $m->where($where)->count();
    	//每页显示条数
    	$num = 12;
    	$page = new \Think\Page($count,$num);
    	$obj = pagestyle($page);
    	$show = $obj->show();
    	$result = $m->where($where)->order(array('id'=>'DESC'))->limit(limitbakstr($obj))->select();
    	$this->assign('page',$show);
    	$this->assign('filmlist',$result);
    	$this->assign('empty',article_empty('article'));
		$this->display();
    }
    
    /*
     * 电影分类
     */
    public function fcolumn(){
    
    	$m = M('ehrcompany_singger',null,'ODDH5_DB_CONFIG1');
    	$where['type'] = 6;
    	$result = $m->where($where)->order(array('sort'=>'DESC'))->select();
    	$this->assign('filmlist',$result);
    	$this->assign('empty',article_empty('article'));
    	$this->display();
    }
    
    /*
     * 编辑电影分类
     */
    public function fcolumnedit(){
    	$id = I('get.id');
    	if(!empty($id)){
    		$m = M('ehrcompany_singger',null,'ODDH5_DB_CONFIG1');
    		$where['id'] = $id;
    		$result = $m->where($where)->find();
    		$this->assign('filmpro',$result);
    		$this->assign('empty',article_empty('article'));
    		$this->display();
    	}else{
    		$this->error('参数错误','',1);
    	}
    	
    }
    
    /*
     * 显示编辑电影
     */
    public function fedit(){
    	$id = I('get.id');
    	if(!empty($id)){
    		$m = M('ehrcompany_singer_resource_video',null,'ODDH5_DB_CONFIG1');
    		$where['id'] = $id;
    		$result = $m->where($where)->find();
    		$this->assign('filmpro',$result);
    		$this->assign('singger_info_id',$this->singger_info_id());
    		$this->assign('video_type',$this->video_type());
    		$this->assign('empty',article_empty('article'));
    		$this->display();
    	}else{
    		$this->error('参数错误','',1);
    	}
    	 
    }
    
    /*
     * 添加电影页面
     */
    public function fadd(){
    	
    	$this->assign('singger_info_id',$this->singger_info_id());
    	$this->assign('video_type',$this->video_type());
    	$this->display();
    }
    protected function singger_info_id(){
    	$m = M('ehrcompany_singger',null,'ODDH5_DB_CONFIG1');
    	$where['type'] = array('in','5,6');
    	$result = $m->where($where)->order('id DESC')->select();
    	return $result;
    }
    protected function video_type(){
    	$arr = array(
    			'3'=>'免费观影',
    			'2'=>'大家访谈',
    			'1'=>'抢先看',
    	);
    	foreach ($arr as $key=>$v){
    		$str .= "<option value=".$key.">".$v."</option>";
    	}
    	return $str;
    }
    
    /*
     * 添加电影分类
     */
    public function fcladd(){
    
    	$m = M('ehrcompany_singger',null,'ODDH5_DB_CONFIG1');
    	$rules = array(
    			array('name','require','电影名称不能为空！'),
    	);
    	if(!$m->validate($rules)->create()){
    		$this->error($m->getError(),'',1);
    	}else{
    		$m->name = I("post.name");
    		$m->filmlink = html_entity_decode(I("post.filmlink"));
    		$m->h_url = "http://h5.hrtv.cn".I("post.thumbimg");
    		$m->content = html_entity_decode(I('post.content'));
    		$m->sort = trim(I("post.sort"));
    		$m->type = 6;
    		/*其他无关字段开始*/
    		$m->version = 1;
    		$m->country = 1;
    		$m->flower_num = 1;
    		$m->occupation = 1;
    		/*其他无关字段结束*/
    		$result = $m->add();
    		if($result){
    			$this->success('添加电影分类成功');
    		}else{
    			$this->error('更新跳转地址失败','',1);
    		}
    	}
    }
    
    /*
     * 编辑电影分类
     */
    public function fcledit(){
    	$id = I('post.hiddenid');
    	$m = M('ehrcompany_singger',null,'ODDH5_DB_CONFIG1');
    	$rules = array(
    			array('name','require','电影名称不能为空！'),
    	);
    	if(!$m->validate($rules)->create()){
    		$this->error($m->getError(),'',1);
    	}else{
    		$m->name = I("post.name");
    		$m->filmlink = html_entity_decode(I("post.filmlink"));
    		if(strstr(I("post.thumbimg"),'http://h5.hrtv.cn')==true){
    			$img = I("post.thumbimg");
    		}else{
    			$img = "http://h5.hrtv.cn".I("post.thumbimg");
    		}
    		$m->h_url = $img;
    		$m->content = html_entity_decode(I('post.content'));
    		$m->sort = trim(I("post.sort"));
    		$m->type = 6;
    		$m->ftype = I("post.ftype");
    		$m->fbrowtime = I("post.fbrowtime");
    		/*其他无关字段开始*/
    		$m->version = 1;
    		$m->country = 1;
    		$m->flower_num = 1;
    		$m->occupation = 1;
    		/*其他无关字段结束*/
    		$result = $m->where(array('id'=>$id))->save();
    		if($result){
    			$this->success('编辑电影分类成功','fcolumn');
    		}else{
    			$this->error('更新跳转地址失败','',1);
    		}
    	}
    }
    
    
    
    /*
     * 添加电影
     */
    public function add(){

    	$m = M('ehrcompany_singer_resource_video',null,'ODDH5_DB_CONFIG1');
    	$rules = array(
    		array('title','require','标题不能为空！'),
    		array('thumbimg','require','视频封面不能为空！'),
    		array('video_url','require','标题地址不能为空！'),
    	);
    	if(!$m->validate($rules)->create()){
    		$this->error($m->getError(),'',1);
    	}else{
    		$m->title = I("post.title");
    		$m->video_img = "http://h5.hrtv.cn".I("post.thumbimg");
    		$m->content = html_entity_decode(I('post.content'));
    		$m->singger_info_id = I("post.singger_info_id");
    		$m->video_type = I("post.video_type");
    		$m->video_type = I("post.video_type");
    		$m->video_url = I("post.video_url");
			if(empty(I("post.isc")) || I("post.isc")==0){
				$isc = 0;
			}else{
				$isc = I("post.isc");
			}
    		$m->isc = $isc;
    		$m->issuer = I("post.issuer");
    		$m->add_time = I("post.add_time");
    		$m->type = 6;
    		/*其他无关字段开始*/
    		$m->version = 1;
    		$m->del_time = I("post.add_time");
    		$m->flower_num = 1;
    		$m->isdel = 0;
    		$m->visit_num = 1;
    		$m->version = 1;
    		$m->version = 1;
    		$m->version = 1;
    		/*其他无关字段结束*/
    		$result = $m->add();
    		if($result){
    			$this->success('添加成功');
    		}else{
    			$this->error('更新跳转地址失败','',1);
    		}
    	}


    }
    
    /*
     * 删除电影
     */
    public function delete(){
    	$id = I('get.id');
    	if(!empty($id)){
    		$m = M('ehrcompany_singer_resource_video',null,'ODDH5_DB_CONFIG1');
    		$m->isdel = 1;
    		$reuslt = $m->where(array('id'=>$id))->save();
    		if($reuslt){
    			$this->success('删除成功');
    		}else{
    			$this->error('删除失败','',1);
    		}
    	}else{
    		$this->error('参数错误','',1);
    	}

    }
    /*
     * 编辑电影
     */
    public function feditpro(){
    	$id = I('post.hiddenid');
    	$m = M('ehrcompany_singer_resource_video',null,'ODDH5_DB_CONFIG1');
    	$rules = array(
    			array('title','require','标题不能为空！'),
    			array('thumbimg','require','视频封面不能为空！'),
    			array('video_url','require','标题地址不能为空！'),
    	);
    	if(!$m->validate($rules)->create()){
    		$this->error($m->getError(),'',1);
    	}else{
    		$m->title = I("post.title");
    		if(strstr(I("post.thumbimg"),'http://h5.hrtv.cn')==true){
    			$img = I("post.thumbimg");
    		}else{
    			$img = "http://h5.hrtv.cn".I("post.thumbimg");
    		}
    		$m->video_img = $img;
    		$m->content = html_entity_decode(I('post.content'));
    		$m->singger_info_id = I("post.singger_info_id");
    		$m->video_type = I("post.video_type");
    		$m->video_url = html_entity_decode(I("post.video_url"));
    		if(empty(I("post.isc")) || I("post.isc")==0){
    			$isc = 0;
    		}else{
    			$isc = I("post.isc");
    		}
    		$m->isc = $isc;
    		$m->issuer = I("post.issuer");
    		$m->add_time = I("post.add_time");
    		$m->type = 6;
    		/*其他无关字段开始*/
    		$m->version = 1;
    		$m->del_time = I("post.add_time");
    		$m->flower_num = 1;
    		$m->isdel = 0;
    		$m->visit_num = 1;
    		$m->version = 1;
    		$m->version = 1;
    		$m->version = 1;
    		/*其他无关字段结束*/
    		$result = $m->where(array('id'=>$id))->save();
    		if($result){
    			$this->success('编辑成功','flist');
    		}else{
    			$this->error('更新跳转地址失败','',1);
    		}
    	}
    
    
    }
   


}